<?php
namespace Api\Controller;
use Api\Controller\CommonController;
use Think\Log;
/**
 * 模块
 * @author wangdong
 */
class ReviewController extends CommonController
{
    public function submit()
    {
        $_validate = array(
            array('carId', '车辆ID必须填写'),
            array('content', '内容必须填写'),
            array('type', '类型必须填写')
        );
        if (!$this->validate($_validate)) {
            $this->errorReturn($this->getError());
        }
        $data = $this->getData();
        $data['addtime'] = time();
        $feedbackdb = M('feedback');
        $feedbackdb->add($data);
        $this->successReturn('操作成功');
    }


    public function listreview(){
        $_validate = array(
            array('carId', '车辆ID必须填写'),
            array('type', '类型必须填写')
        );
        if (!$this->validate($_validate)) {
            $this->errorReturn($this->getError());
        }
        $data = $this->getData();
        $reviewdb = M('Feedback');
        $page = $data['page'] ? $data['page'] : 1;
        $pagesize = $data['pagesize'] ? $data['pagesize'] : 5;
        $limit = ($page - 1) * $pagesize . "," . $pagesize;
        if($data['type']==1){
            $where = 'type=1 and (carId='.$data['carId'].' or result=1)';
        }else{
            $where = 'type=' . $data['type'].' and carId='.$data['carId'];
        }
        $dbdata = $reviewdb ->where($where)->limit($limit)->order('addtime desc')->select();
        $this->successReturn('获取反馈信息成功', $dbdata);
    }
}